package com.szzg10.thinking.chapter11;

import java.util.AbstractCollection;
import java.util.Iterator;

public class CollectionSequence extends AbstractCollection<Pet> {

	private Pet[] pets = {new Rat(), new Manx(), new Cymric(), new Mutt(), new Pug(), new Cymric(), new Pug(), new Manx()};
	
	public static void main(String[] args) {
		CollectionSequence collectionSequence  = new CollectionSequence();
		InterfaceVsInterator.display(collectionSequence);
		InterfaceVsInterator.display(collectionSequence.iterator());
	}
	
	@Override
	public Iterator<Pet> iterator() {
		return new Iterator<Pet>() {
			private int index;
			
			@Override
			public boolean hasNext() {
				return pets.length > index;
			}

			@Override
			public Pet next() {
				return pets[index++];
			}

			@Override
			public void remove() {
				throw new UnsupportedOperationException();
			}
			
		};
	}

	@Override
	public int size() {
		return pets.length;
	}

}
